package org.jiajie.coffeecodes.concurrent.mutual.exclusion;

import java.util.concurrent.TimeUnit;

/**
 * @author jay
 */
public class StopThread {

    private static volatile Boolean stopRequested;

//    private static synchronized void requestStop(){
//        stopRequested = true;
//    }
//
//    private static synchronized Boolean stopRequested(){
//        return stopRequested;
//    }

    public static void main(String[] args) throws InterruptedException {
        Thread backgroundThread = new Thread(() -> {
            int i = 0;
            while (!stopRequested){
                i++;
            }
        });
        backgroundThread.start();
        TimeUnit.SECONDS.sleep(1);
        stopRequested = true;
    }
}
